﻿using UnityEngine;
using UnityEngine.UI;

public class BGImage : MonoBehaviour {

	public Sprite[] BgSprites;		//背景精灵集合

	void Start () {
		//DontDestroyOnLoad (this.gameObject);
	}

	public Sprite OnGetBG()
	{
		int n;
		if (PlayerPrefs.HasKey("BGImage")) {
			n = PlayerPrefs.GetInt ("BGImage");
			if (n < BgSprites.Length && n >= 0) {
				return BgSprites[n];
			}

		}
		n = Random.Range (0, BgSprites.Length);
		PlayerPrefs.SetInt ("BGImage",n);
		return BgSprites[n];
	}

	public Sprite OnChangeBG()
	{
		int n = Random.Range (0, BgSprites.Length);
		PlayerPrefs.SetInt ("BGImage",n);
		return BgSprites[n];
	}
}
